import pymysql


def getconn():
    return pymysql.connect(host='127.0.0.1',user='root',password='2c15161c',db='chaos_platform',charset='utf8',cursorclass=pymysql.cursors.DictCursor)
#查询
def query_data(sql):
    conn =getconn()
    try:
        cursor =conn.cursor(pymysql.cursors.DictCursor)
        cursor.execute(sql)
        return cursor.fetchall()
    finally:
        conn.close()

#新增
def insert_or_updata_data(sql):
    conn = getconn()
    try:
        cursor = conn.cursor()
        cursor.execute(sql)
        conn.commit()
        return cursor.fetchall()
    finally:
        conn.close()
#删除
def delete_or_data(sql):
    conn=getconn()
    try:
        cursor=conn.cursor()
        cursor.execute(sql)
        conn.commit()
        return cursor.fetchall()
    finally:
        conn.close()



if __name__ =='__main__':
    sql='select * from testcase_execute'
    datas =query_data(sql)
    import pprint
    pprint.pprint(datas)
